﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    public class Singleton
    {
        static Singleton single; //定义类的对象
                                 //线程锁资源
        static public readonly object obj = new object();//线程锁资源
        private Singleton() { }//私有构造函数


        public static Singleton GetInstnace()
        {
            if (single == null)
            {
                lock (obj)
                {
                    if (single == null)
                    {
                        single = new Singleton();
                    }
                }
            }
            return single;

        }
        public string qqqq()
        {
            return "单例模式";
        }

    }
    public class Singleton1
    {
        /// <summary>
        /// 静态初始化
        /// </summary>
        private readonly Singleton1 instance = new Singleton1();
        private Singleton1() { }//私有构造函数（防止外部实例化）
        public Singleton1 GetInstance()
        {
            return instance;
        }
        public void aaa()
        {

        }
       
    
    }
}
